#include <stdio.h>
#include <flgrCoreData.h>
#include <flgrCoreDataIO.h>
#include <flgrCoreCopy.h>
#include <flgrMorphoSkiz.h>
#include "../macro.h"




/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_label types
/////////////////////////////////////////////////////////////////////////
#define tstDilate_Preserving_Skiz(dtype)				\
									\
  dtype rawsrc[]={1,1,0,0,2,2,2,0,0,0,0,0,0,0,0,0,3,3,3,3,		\
		  1,1,0,2,2,2,2,2,0,0,0,0,0,0,0,0,0,0,0,0,		\
		  0,0,0,2,2,2,2,2,0,0,0,0,0,0,0,4,4,4,4,4,		\
		  0,0,0,2,2,2,2,2,0,0,0,5,5,5,0,0,0,4,4,4,		\
		  0,0,0,2,2,2,2,2,0,0,5,5,5,5,5,0,0,0,0,0,		\
		  0,0,0,2,2,2,2,2,0,0,5,5,5,5,5,0,0,0,0,0,		\
		  0,0,0,2,2,2,2,2,0,0,5,5,5,5,0,0,0,0,0,0,		\
		  0,0,0,0,2,2,2,0,0,0,0,0,0,0,6,6,6,6,6,6};		\
									\
  dtype rawref[]={1,1,0,2,2,2,2,2,0,0,0,0,0,0,0,3,3,3,3,3,		\
		  1,1,0,2,2,2,2,2,2,0,0,0,0,0,0,4,0,0,0,0,		\
		  1,1,2,2,2,2,2,2,2,0,5,5,5,5,4,4,4,4,4,4,		\
		  0,0,2,2,2,2,2,2,2,0,5,5,5,5,5,0,4,4,4,4,		\
		  0,0,2,2,2,2,2,2,2,5,5,5,5,5,5,5,4,4,4,4,		\
		  0,0,2,2,2,2,2,2,2,5,5,5,5,5,5,5,0,0,0,0,		\
		  0,0,2,2,2,2,2,2,2,5,5,5,5,0,0,6,6,6,6,6,		\
		  0,0,0,2,2,2,2,2,2,0,5,5,5,0,6,6,6,6,6,6};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  int ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,20,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,20,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,20,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb = flgr2d_create_neighborhood(3,3,1,				\
				   flgr_get_type_from_string(#dtype),	\
				   FLGR_HEX, FLGR_6_CONNEX);		\
  									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
									\
  ret=flgr2d_dilate_preserving_skiz(img,imgsrc,nhb);			\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

int testdilate_preserving_skiz_fgUINT8(void) {
  tstDilate_Preserving_Skiz(fgUINT8);
}
int testdilate_preserving_skiz_fgUINT16(void) {
  tstDilate_Preserving_Skiz(fgUINT16);
}
int testdilate_preserving_skiz_fgUINT32(void) {
  tstDilate_Preserving_Skiz(fgUINT32);
}
int testdilate_preserving_skiz_fgINT8(void) {
  tstDilate_Preserving_Skiz(fgINT8);
}
int testdilate_preserving_skiz_fgINT16(void) {
  tstDilate_Preserving_Skiz(fgINT16);
}
int testdilate_preserving_skiz_fgINT32(void) {
  tstDilate_Preserving_Skiz(fgINT32);
}
int testdilate_preserving_skiz_fgFLOAT32(void) {
  tstDilate_Preserving_Skiz(fgFLOAT32);
}
int testdilate_preserving_skiz_fgFLOAT64(void) {
  tstDilate_Preserving_Skiz(fgFLOAT64);
}


/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_label types
/////////////////////////////////////////////////////////////////////////
#define tstDilate_Preserving_Skiz2(dtype)				\
									\
  dtype rawsrc[]={  0,  0,  0,  1,  1,  1,  1,  1,  0,  5,		\
		    0,  0,  0,  1,  1,  1,  1,  1,  0,  5,		\
		    0,  0,  0,  1,  1,  1,  1,  1,  0,  0,		\
		    0,  0,  0,  1,  1,  1,  1,  1,  0,  0,		\
		    0,  0,  0,  1,  1,  1,  1,  1,  0,  0,		\
		    0,  0,  0,  1,  1,  1,  1,  1,  0,  0,		\
		    2,  2,  2,  0,  0,  0,  0,  0,  6,  6,		\
		    2,  2,  0,  0,  0,  0,  0,  0,  6,  6};		\
									\
  dtype rawref[]={  0,  0,  1,  1,  1,  1,  1,  1,  0,  5,		\
		    0,  0,  1,  1,  1,  1,  1,  1,  0,  5,		\
		    0,  0,  1,  1,  1,  1,  1,  1,  1,  5,		\
		    0,  0,  1,  1,  1,  1,  1,  1,  1,  0,		\
		    0,  0,  1,  1,  1,  1,  1,  1,  1,  0,		\
		    2,  2,  0,  1,  1,  1,  1,  1,  0,  6,		\
		    2,  2,  2,  0,  1,  1,  1,  0,  6,  6,		\
		    2,  2,  2,  0,  0,  0,  0,  6,  6,  6};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  int ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb = flgr2d_create_neighborhood(3,3,1,				\
				   flgr_get_type_from_string(#dtype),	\
				   FLGR_CROSS, FLGR_4_CONNEX);		\
 									\
  nhb->shape = FLGR_USER_SHAPE;						\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
									\
  ret=flgr2d_dilate_preserving_skiz(img,imgsrc,nhb);			\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

int testdilate_preserving_skiz2_fgUINT8(void) {
  tstDilate_Preserving_Skiz2(fgUINT8);
}
int testdilate_preserving_skiz2_fgUINT16(void) {
  tstDilate_Preserving_Skiz2(fgUINT16);
}
int testdilate_preserving_skiz2_fgUINT32(void) {
  tstDilate_Preserving_Skiz2(fgUINT32);
}
int testdilate_preserving_skiz2_fgINT8(void) {
  tstDilate_Preserving_Skiz2(fgINT8);
}
int testdilate_preserving_skiz2_fgINT16(void) {
  tstDilate_Preserving_Skiz2(fgINT16);
}
int testdilate_preserving_skiz2_fgINT32(void) {
  tstDilate_Preserving_Skiz2(fgINT32);
}
int testdilate_preserving_skiz2_fgFLOAT32(void) {
  tstDilate_Preserving_Skiz2(fgFLOAT32);
}
int testdilate_preserving_skiz2_fgFLOAT64(void) {
  tstDilate_Preserving_Skiz2(fgFLOAT64);
}


/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_label types
/////////////////////////////////////////////////////////////////////////
#define tstDilate_Preserving_Skiz3(dtype)				\
									\
  dtype rawsrc[]={  0,  0,  0,  1,  1,  1,  1,  1,  0,  0,		\
		    0,  0,  0,  1,  1,  1,  1,  1,  0,  0,		\
		    0,  0,  0,  1,  1,  1,  1,  1,  0,  0,		\
		    0,  0,  0,  1,  1,  1,  1,  1,  0,  0,		\
		    0,  0,  0,  1,  1,  1,  1,  1,  0,  0,		\
		    0,  0,  0,  1,  1,  1,  1,  1,  0,  0,		\
		    2,  2,  0,  0,  0,  0,  0,  0,  0,  0,		\
		    2,  2,  0,  0,  0,  0,  0,  0,  0,  0};		\
									\
  dtype rawref[]={  0,  0,  1,  1,  1,  1,  1,  1,  1,  0,		\
		    0,  0,  1,  1,  1,  1,  1,  1,  1,  0,		\
		    0,  0,  1,  1,  1,  1,  1,  1,  1,  0,		\
		    0,  0,  1,  1,  1,  1,  1,  1,  1,  0,		\
		    0,  0,  1,  1,  1,  1,  1,  1,  1,  0,		\
		    2,  2,  0,  1,  1,  1,  1,  1,  1,  0,		\
		    2,  2,  0,  1,  1,  1,  1,  1,  1,  0,		\
		    2,  2,  2,  0,  0,  0,  0,  0,  0,  0};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  int ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb = flgr2d_create_neighborhood(3,3,1,				\
				   flgr_get_type_from_string(#dtype),	\
				   FLGR_RECT, FLGR_8_CONNEX);		\
  nhb->shape = FLGR_USER_SHAPE;						\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
									\
  ret=flgr2d_dilate_preserving_skiz(img,imgsrc,nhb);			\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

int testdilate_preserving_skiz3_fgUINT8(void) {
  tstDilate_Preserving_Skiz3(fgUINT8);
}
int testdilate_preserving_skiz3_fgUINT16(void) {
  tstDilate_Preserving_Skiz3(fgUINT16);
}
int testdilate_preserving_skiz3_fgUINT32(void) {
  tstDilate_Preserving_Skiz3(fgUINT32);
}
int testdilate_preserving_skiz3_fgINT8(void) {
  tstDilate_Preserving_Skiz3(fgINT8);
}
int testdilate_preserving_skiz3_fgINT16(void) {
  tstDilate_Preserving_Skiz3(fgINT16);
}
int testdilate_preserving_skiz3_fgINT32(void) {
  tstDilate_Preserving_Skiz3(fgINT32);
}
int testdilate_preserving_skiz3_fgFLOAT32(void) {
  tstDilate_Preserving_Skiz3(fgFLOAT32);
}
int testdilate_preserving_skiz3_fgFLOAT64(void) {
  tstDilate_Preserving_Skiz3(fgFLOAT64);
}

/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_label types
/////////////////////////////////////////////////////////////////////////
#define tstDilate_Preserving_Skiz4(dtype)				\
									\
  dtype rawsrc[]={  0,  0,  0,  1,  1,  1,  1,  1,  0,  0,		\
		    0,  0,  0,  1,  1,  1,  1,  1,  0,  0,		\
		    0,  0,  0,  1,  1,  1,  1,  1,  0,  0,		\
		    0,  0,  0,  1,  1,  1,  1,  1,  0,  0,		\
		    0,  0,  0,  1,  1,  1,  1,  1,  0,  0,		\
		    0,  0,  0,  1,  1,  1,  1,  1,  0,  0,		\
		    2,  2,  0,  0,  0,  0,  0,  0,  0,  0,		\
		    2,  2,  0,  0,  0,  0,  0,  0,  0,  0};		\
									\
  dtype rawref[]={  0,  0,  1,  1,  1,  1,  1,  1,  1,  0,		\
		    0,  0,  1,  1,  1,  1,  1,  1,  1,  0,		\
		    0,  0,  1,  1,  1,  1,  1,  1,  1,  0,		\
		    0,  0,  1,  1,  1,  1,  1,  1,  1,  0,		\
		    0,  0,  1,  1,  1,  1,  1,  1,  1,  0,		\
		    2,  2,  0,  1,  1,  1,  1,  1,  1,  0,		\
		    2,  2,  0,  1,  1,  1,  1,  1,  1,  0,		\
		    2,  2,  2,  0,  0,  0,  0,  0,  0,  0};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  int ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb = flgr2d_create_neighborhood(3,3,1,				\
				   flgr_get_type_from_string(#dtype),	\
				   FLGR_RECT, FLGR_8_CONNEX);		\
  									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
									\
  ret=flgr2d_dilate_preserving_skiz(img,imgsrc,nhb);			\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

int testdilate_preserving_skiz4_fgUINT8(void) {
  tstDilate_Preserving_Skiz4(fgUINT8);
}
int testdilate_preserving_skiz4_fgUINT16(void) {
  tstDilate_Preserving_Skiz4(fgUINT16);
}
int testdilate_preserving_skiz4_fgUINT32(void) {
  tstDilate_Preserving_Skiz4(fgUINT32);
}
int testdilate_preserving_skiz4_fgINT8(void) {
  tstDilate_Preserving_Skiz4(fgINT8);
}
int testdilate_preserving_skiz4_fgINT16(void) {
  tstDilate_Preserving_Skiz4(fgINT16);
}
int testdilate_preserving_skiz4_fgINT32(void) {
  tstDilate_Preserving_Skiz4(fgINT32);
}
int testdilate_preserving_skiz4_fgFLOAT32(void) {
  tstDilate_Preserving_Skiz4(fgFLOAT32);
}
int testdilate_preserving_skiz4_fgFLOAT64(void) {
  tstDilate_Preserving_Skiz4(fgFLOAT64);
}


/////////////////////////////////////////////////////////////////////////
// Test Macro for all flgr2d_label types
/////////////////////////////////////////////////////////////////////////
#define tstDilate_Preserving_Skiz5(dtype)				\
									\
  dtype rawsrc[]={  3,  3,  0,  1,  1,  1,  1,  1,  0,  5,		\
		    3,  3,  0,  1,  1,  1,  1,  1,  0,  5,		\
		    0,  0,  0,  1,  1,  1,  1,  1,  1,  0,		\
		    0,  0,  0,  1,  1,  1,  1,  1,  1,  1,		\
		    0,  0,  0,  1,  1,  1,  1,  1,  0,  0,		\
		    0,  0,  0,  1,  1,  1,  1,  1,  0,  0,		\
		    2,  2,  0,  0,  0,  0,  0,  0,  0,  4,		\
		    2,  2,  0,  0,  0,  0,  0,  0,  4,  4};		\
									\
  dtype rawref[]={  3,  3,  0,  1,  1,  1,  1,  1,  0,  5,		\
		    3,  3,  0,  1,  1,  1,  1,  1,  0,  5,		\
		    3,  3,  1,  1,  1,  1,  1,  1,  0,  0,		\
		    0,  0,  1,  1,  1,  1,  1,  1,  1,  1,		\
		    0,  0,  1,  1,  1,  1,  1,  1,  1,  1,		\
		    2,  2,  0,  1,  1,  1,  1,  1,  1,  4,		\
		    2,  2,  0,  1,  1,  1,  1,  0,  4,  4,		\
		    2,  2,  2,  0,  0,  0,  0,  4,  4,  4};		\
									\
  FLGR_Data2D *imgsrc, *imgref, *img, *nhb;				\
  int ret;								\
									\
  imgsrc = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  imgref = flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  img =    flgr2d_create_##dtype(8,10,1,FLGR_NO_SHAPE,FLGR_NO_CONNEX);	\
  nhb = flgr2d_create_neighborhood(3,3,1,				\
				   flgr_get_type_from_string(#dtype),	\
				   FLGR_HEX, FLGR_6_CONNEX);		\
									\
  nhb->shape = FLGR_USER_SHAPE;						\
									\
  flgr2d_import_raw_ptr(imgsrc,rawsrc);					\
  flgr2d_import_raw_ptr(imgref,rawref);					\
									\
									\
  ret=flgr2d_dilate_preserving_skiz(img,imgsrc,nhb);			\
									\
  check_and_display_data2d(imgref,img,ret);				\
									\
  flgr2d_destroy(imgsrc);						\
  flgr2d_destroy(imgref);						\
  flgr2d_destroy(img);							\
  flgr2d_destroy(nhb);							\
									\
  return 1

int testdilate_preserving_skiz5_fgUINT8(void) {
  tstDilate_Preserving_Skiz5(fgUINT8);
}
int testdilate_preserving_skiz5_fgUINT16(void) {
  tstDilate_Preserving_Skiz5(fgUINT16);
}
int testdilate_preserving_skiz5_fgUINT32(void) {
  tstDilate_Preserving_Skiz5(fgUINT32);
}
int testdilate_preserving_skiz5_fgINT8(void) {
  tstDilate_Preserving_Skiz5(fgINT8);
}
int testdilate_preserving_skiz5_fgINT16(void) {
  tstDilate_Preserving_Skiz5(fgINT16);
}
int testdilate_preserving_skiz5_fgINT32(void) {
  tstDilate_Preserving_Skiz5(fgINT32);
}
int testdilate_preserving_skiz5_fgFLOAT32(void) {
  tstDilate_Preserving_Skiz5(fgFLOAT32);
}
int testdilate_preserving_skiz5_fgFLOAT64(void) {
  tstDilate_Preserving_Skiz5(fgFLOAT64);
}

